<template>
	<div class="msg">
		<view>
			<input class="inputStyle" placeholder="学号" v-model="stu.sno" />
		</view>
		<view>
			<input class="inputStyle" placeholder="姓名" v-model="stu.name" />
		</view>
		<view>
			<picker  @click="inputClick('sex')" @change="bindPickerChange" :value="index" :range="sex">
				<input class="inputStyle" placeholder="性别" disabled v-model="stu.sex" />
				<view class="imgRight"></view>
			</picker>
		</view>
		<view>
			<picker  @click="inputClick('nation')" @change="bindPickerChange" :value="index" :range="nation">
				<input class="inputStyle" placeholder="民族" disabled v-model="stu.nation" />
				<view class="imgRight"></view>
			</picker>
		</view>
		<view>
			<picker  @click="inputClick('political')" @change="bindPickerChange" :value="index" :range="political">
				<input class="inputStyle" placeholder="政治面貌" disabled v-model="stu.political" />
				<view class="imgRight"></view>
			</picker>
		</view>
		<view>
			<picker  @click="inputClick('region')" @change="bindPickerChange" :value="index" :range="region">
				<input class="inputStyle" placeholder="生源地" disabled v-model="stu.region" />
				<view class="imgRight"></view>
			</picker>
		</view>
		<view>
			<input class="inputStyle" placeholder="毕业中学" v-model="stu.midSchool" />
		</view>
		<!-- <view>
			<input class="inputStyle" placeholder="身份证号" v-model="stu.id" />
		</view>
		-->
		<view>
			<input class="inputStyle" placeholder="考生号" v-model="stu.canNum" />
		</view>
		<view>
			<input class="inputStyle" type="password" placeholder="密码" v-model="stu.pwd" />
		</view>
		<view>
			<input class="inputStyle" placeholder="分数" v-model="stu.fraction" />
		</view>
		<view>
			<picker @click="inputClick('category')" @change="bindPickerChange" id="category" :value="index" :range="category">
				<input class="inputStyle" placeholder="招生类别" disabled v-model="stu.category" />
				<view class="imgRight"></view>
			</picker>
		</view>
		<view>
			<picker @click="inputClick('tno')" @change="bindPickerChange" id="tno" :value="index" :range="tno">
				<input class="inputStyle" placeholder="教师编号" disabled v-model="stu.tno" />
				<view class="imgRight"></view>
			</picker>
		</view>
		<view>
			<picker @click="inputClick('hno')" @change="bindPickerChange" id="hno" :value="index" :range="hno">
				<input class="inputStyle" placeholder="宿舍号" disabled v-model="stu.hno" />
				<view class="imgRight"></view>
			</picker>
		</view>
		<br/>
		<view>
			<button type="default" form-type="submit" class="loginBtn" @click="forget">下一步</button>
		</view>
	</div>
</template>

<script>
	const {addStudent} = require('../../utils/api.js')
	export default {
		data() {
			return {
				src:require('../../static/images/icon/right.png'),
				nation: ['汉族', '畲族', '维吾尔族', '蒙古族'],
				political: ['党员', '团员', '清白'],
				region: ['江西', '福建', '湖南'],
				category: ['统招', '非统招'],
				sex: ['男', '女'],
				tno: ['1002117030', '1002117031','1002117032','1002117033'],
				hno: ['210', '211','212','213'],
				index: 0,
				stu:{
					sno:"",
					pwd:"",
					name:"",
					sex:"",
					nation:"",
					political:"",
					region:"",
					midSchool:"",
					canNum:"",
					fraction:"",
					category:"",
					tno:"",
					hno:""
				},
				id:''
			}
		},
		methods:{
			inputClick(id){
				this.id = id;
			},
			bindPickerChange: function(e) {
				this.index = e.target.value;
				if(this.id == 'region'){
					this.stu.region = this.region[this.index];
				}else if(this.id == 'category'){
					this.stu.category = this.category[this.index];
				}else if(this.id == 'nation'){
					this.stu.nation = this.nation[this.index];
				}else if(this.id == 'political'){
					this.stu.political = this.political[this.index];
				}else if(this.id == 'sex'){
					this.stu.sex = this.sex[this.index];
				}else if(this.id == 'tno'){
					this.stu.tno = this.tno[this.index];
				}else if(this.id == 'hno'){
					this.stu.hno = this.hno[this.index];
				}
			},
			forget(){
				addStudent(this.stu).then(data=>{
					console.log(data)
					uni.showModal({
						content: data.msg,
						showCancel: false
					});
					if(data.code === 200){
						uni.navigateTo({
							url: 'login'
						});
					}
				})
			}
		}
	}
</script>

<style scoped src="../../static/css/login.css"></style>
